package controllers;

import models.Commont;
import service.CommontInterface;
import service.impl.CommontImpl;
import utils.JsonUtil;

import java.util.List;
import java.util.Map;

/**
 * 评论action
 */
public class CommontAction extends Application {
    //获取评论列表
    public static void getCommontListByPage(String params) throws Exception {
        Map<String, Object> paramsMap = JsonUtil.paseJson2Map(params);
        Integer contentId = (Integer) paramsMap.get("contentId");
        Integer commontType = (Integer) paramsMap.get("commontType");
        Integer pageSize = (Integer) paramsMap.get("pageSize");
        Integer pageNum = (Integer) paramsMap.get("pageNum");
        CommontInterface commontInterface = new CommontImpl();
        List<Commont> list = commontInterface.getCommontListByPage(contentId, commontType, pageSize, pageNum);
        renderText(JsonUtil.parseObject(list));
    }

    //创建单个评论
    public static void commont(String params){
        Commont commont = (Commont) JsonUtil.readJson2Entity(params, Commont.class);
        CommontInterface commontInterface = new CommontImpl();
        commontInterface.createCommont(commont);
    }
}
